<?php

namespace App\Models\Sys;

use Illuminate\Database\Eloquent\Model;

class Permission extends Model
{
    protected $table = 'sys_menu';

    protected $fillable=['parent_id','code','name','type','permission','icon','path','component','sort','forbidden','create_by','created_at','update_by','updated_at'];

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];
    //获取所有权限列表
    public function getAllPermission($tree=true)
    {

        $data=$this->get();
        if($tree){
            return  getTree($data);
        }
        else{
            return array_column($data->toArray(),null,'id');
        }

        
    }


    public function getAllMenu($param)
    {
        $pageSize = $param['size'] ?? 10;
        return $this->paginate($pageSize);
    }


    public function getFirst()
    {
        return $this->select('name','id')->where('parent_id','=',0)->get();
    }
}
